#pragma once

class nQueen {
public:
    nQueen(int queenTotal);
    virtual ~nQueen();
    int calculate();
    
private:
    inline bool isPlaceable() const{
        for(int i = 0; i < queenPlaced; ++i){
            int line = queensLine[i], row = queensRow[i];
            if(line == checkerLine) return false;
            if(row == checkerRow) return false;
            if(row + line == checkerRow + checkerLine) return false;
            if(checkerLine - line == checkerRow - row) return false;
        }
        return true;
    }
    
    inline void back(){
        checkerLine = queensLine[--queenPlaced];
        checkerRow = queensRow[queenPlaced];
        moveNext();
    }
    
    inline void moveNext(){
        checkerRow++;
        if(checkerRow == queenTotal){
            back();
        }
    }
    
    const int queenTotal;
    int checkerLine;
    int checkerRow;
    int queenPlaced;
    int *const queensRow;
    int *const queensLine;
};
